package com.xuanyue.componentim.redis;

/**
 * 记录所有redisKey格式
 */
public class RedisKeys {

    /* 在线状态 key-> im:online:#{userId} value-> UUID[str]  */
    private static final String ONLINE_KEY = "im:online:";

    /* XX人所有接收通道                                       */
    /* im:rChannelKeys:#{userId} --> Hash                  */
    /*                             |————> #{CHANNEL_KEY-1}  */
    /*                             |————> #{CHANNEL_KEY-2}  */
    /*                                                     */
    private static final String CHANNEL_GROUP_KEY = "im:channelGroup:";

    /* XX人对当前人发送的消息 im:rChannelKey:#{sUserId}to#{rUserId} -> List */
    private static final String CHANNEL_KEY = "im:channelKey:";


    /**
     * 获取登录key
     * @param userId
     * @return
     */
    public static String onlineKey( String userId ){
        return ONLINE_KEY + userId;
    }

    /**
     * 获取用户关联通道key
     * @param userId
     * @return
     */
    public static String channelGroupKey( String userId ){
        return CHANNEL_GROUP_KEY + userId;
    }

    /**
     * 获取通道key
     * @param sUserId
     * @param rUserId
     * @return
     */
    public static String channelKey( String sUserId, String rUserId ){
        return CHANNEL_KEY + sUserId + "to" + rUserId;
    }

}
